{% extends 'bootstrap_children.html' %}
{% block content %}
<div id="page-wrapper">
    <div class="row">
         <div class="col-lg-12">
              <h1 class="page-header"><i class="fa  fa-list-ol "></i> 任务列表</h1>
         </div>
                <!-- /.col-lg-12 -->
         
    </div>
    <div class="row">
         <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            	任务列表明细
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="cronTableList">
                                <thead>
                                    <tr>
                                    	<th>任务名称</th>
                                    	<th>用户</th>
                                        <th>分</th>
                                        <th>时</th>
                                        <th>日</th>
                                        <th>月</th>
                                        <th>周</th>
                                        <th>命令</th>
                                        <th>主机</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                	{% for ds in cronList %}
                                		<tr class="odd gradeX">
                                			<td>{{ds.cron_name}} </td>
                                			<td>{{ds.cron_user}} </td>
                                			<td>{{ds.cron_minute}} </td>
                                			<td>{{ds.cron_hour}} </td>
                                			<td>{{ds.cron_day}} </td>
                                			<td>{{ds.cron_month}} </td>
                                			<td>{{ds.cron_week}} </td>
                                			<td>{{ds.cron_command}} </td>
                                			<td>
                             					{{ ds.cron_server.ip }}
                                			</td>
                                			{% if ds.cron_status == 0 %}
                                				<td><button  type="button" class="btn btn-outline btn-warning">未激活</button></td>
                                			{% else %}
                                				<td><button  type="button" class="btn btn-outline btn-success">已激活</button></td>
                                			{% endif %}
                                			<td>
                                				<a href="/cron_mod/{{ds.id}}"><button  type="button" class="btn btn-default"><abbr title="修改资料"><i class="glyphicon glyphicon-edit"></i></button></a>
                                				<button  type="button" class="btn btn-default" onclick="deleteCron(this,{{ds.id}})"><abbr title="删除"><i class="glyphicon glyphicon-trash"></i></button>
                                			</td>
                                		</tr>
                                	{% endfor %}
                                </tbody>
                            </table>
                            <!-- /.table-responsive -->                            
                            <div class="well">
                                <h4>任务管理说明</h4>
                                <p>使用改功能时候会依据数据库里面的计划任务来生成配置文件，再推送到服务器。</p>
                                <a class="btn btn-default btn-lg btn-block" target="_blank" href="/cron_add"><i class="fa fa-plus-circle "></i>新建任务</a>
                            </div>
										{% if cronList %}
											<ul class="pagination">
											        {% if cronList.has_previous %}
											            <li><a href="/cron_log/{{ cronList.previous_page_number }}/">&laquo;</a></li>
											        {% endif %}
											        {% for page in cronList.paginator.page_range %}
											        	{% if cronList.number == page %}
											        		<li class="disabled"><a href="/cron_log/{{page}}/">{{page}}</a></li>
											        	{% else %}
											        		<li><a href="/cron_log/{{page}}/">{{page}}</a></li>
											        	{% endif %}
											        {% endfor %}
											        {% if cronList.has_next %}
											            <li><a href="/cron_log/{{ cronList.next_page_number }}/">&raquo;</a></li>
											        {% endif %}
											</ul>
                     		            {% endif %}	                            
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
    </div>    
    
    <script>
    $(document).ready(function() {
        $('#cronTableList').DataTable({
            responsive: true
        });
    });
    
	function deleteCron(obj,id){
		var txt=  "是否确认删除？";
		var btnObj = $(obj);
		btnObj.attr('disabled',true);
		var option = {
			title: "删除任务",
			btn: parseInt("0011",2),
			onOk: function(){
				$.ajax({
					  type: 'DELETE',
					  url: '/cron_mod/'+id+'/',
				      success:function(response){	
				    	btnObj.removeAttr('disabled');
				    	if (response["code"]=="200"){ 
		                	window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.success);
		                	location.reload('/cron_list/');
		                }
				    	else{
			        		window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.error);
			        	}				            
				      },
		              error:function(response){
		            	btnObj.removeAttr('disabled');
		            	window.wxc.xcConfirm("删除失败！", window.wxc.xcConfirm.typeEnum.error);	
		              }
					});
			},
			onCancel:function(){	
			},
			onClose:function(){
			}
		}
		window.wxc.xcConfirm(txt, "custom", option);			   
	}  
    
    </script>    
{% endblock %}